package service

import (
	"context"
	__ "mt-server/basic/proto"
	"mt-server/handler/model"
	"mt-server/pkg"
)

// 订单支付
func (s *Server) PaymentOrder(_ context.Context, in *__.PaymentOrderReq) (*__.PaymentOrderResp, error) {
	var or model.Order
	var m model.Merchant
	m.NikName = in.Name
	//判断商家是否在线
	err := m.FirstMerchant()
	if err != nil {
		return &__.PaymentOrderResp{
			Msg:  "支付成功",
			Code: 200,
		}, nil
	}
	if m.Status != 1 {
		return &__.PaymentOrderResp{
			Msg:  "商家未在线需审核",
			Code: 500,
		}, nil
	}

	//订单支付
	or = model.Order{
		Amount:   float64(in.Amount),
		UserId:   int32(in.Userid),
		GoodsId:  int32(in.GoodId),
		Quantity: in.Quantity,
	}
	err = or.UpOrder()
	if err != nil {
		return &__.PaymentOrderResp{
			Msg:  "支付失败",
			Code: 500,
		}, nil
	}
	//支付
	pkg.NewPaymentFactory()

	return &__.PaymentOrderResp{
		Msg:  "支付成功",
		Code: 200,
	}, nil
}
